<#ftl/>
package ${controllerPackage};

import ${entityPackage}.${entity};
<#if need_saveDto>
    import ${saveDtoPackage}.${saveDtoClassName};
    import ${voPackage}.${voClassName};
</#if>
<#if need_excelVo>
import ${voPackage}.${excelVoClassName};
</#if>
import ${servicePackage}.${serviceClassName};
import com.qhkj.engineering.common.core.domain.R;
import java.util.List;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;
import com.qhkj.engineering.common.enums.BusinessType;
import com.qhkj.engineering.common.annotation.Log;
import com.qhkj.engineering.common.core.controller.BaseController;
import com.qhkj.engineering.common.core.domain.R;
import com.qhkj.engineering.common.core.page.TableDataInfo;
import com.qhkj.engineering.common.exception.ServiceException;
import com.qhkj.engineering.common.utils.poi.ExcelExportUtil;
import javax.validation.Valid;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
<#if swagger>
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
</#if>
/**
  * <p>
  * ${table.comment!}-- 相关接口
  * </p>
* @author ${author}
* @since ${date}
*/
<#if swagger>
@Api(value = "${table.comment!}相关接口", tags = "${table.comment!}")
</#if>
@RestController
@RequestMapping("/${table.name}")
public class ${controllerClassName} extends BaseController{

    @Resource
    private ${serviceClassName} ${classVar}Service;


    /**
    * 查询列表
    */
    // @PreAuthorize("@ss.hasPermi('${classVar}:list')")
    @GetMapping("/list")
<#if swagger>
    @ApiOperation(value="分页查询${table.comment!}")
</#if>
    public TableDataInfo<<#if need_saveDto>${excelVoClassName}<#else>${entity}</#if>> list(${entity} ${classVar}){
        startPage();
        return getDataTable(${classVar}Service.queryList(${classVar}));
    }

<#if need_excelVo>
    /**
    * 导出${entity}列表
    */
    // @PreAuthorize("@ss.hasPermi('${classVar}:export')")
    @Log(title = "export ${table.comment!}", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    <#if swagger>
    @ApiOperation(value="导出数据")
    </#if>
    public void export(HttpServletResponse response, ${entity} ${classVar}){
        ExcelExportUtil.easyExcelExport(${classVar}Service.queryList(${classVar}), response, ${excelVoClassName}.class, null);

    }
   </#if>
    /**
    * 获取${entity}详细信息
    */
    // @PreAuthorize("@ss.hasPermi('${classVar}:detail')")
    @GetMapping("/detail/{id}")
<#if swagger>
    @ApiOperation(value="获取详细信息")
</#if>
    public R<<#if need_saveDto>${voClassName}<#else>${entity}</#if>> getInfo(@PathVariable("id") <#list table.fields as field><#if field.keyFlag><#--主键java类型-->${field.columnType.type} id</#if></#list>){
        return R.ok(${classVar}Service.getById(id));
    }
    
    /**
    * 新增${table.comment!}
    */
    // @PreAuthorize("@ss.hasPermi('${classVar}:add')")
    @Log(title = "新增${table.comment!}", businessType = BusinessType.INSERT)
    @PostMapping
<#if swagger>
    @ApiOperation(value="新增")
</#if>
    public R add(@RequestBody @Validated <#if need_saveDto>${saveDtoClassName}<#else>${entity}</#if> ${classVar}){
        ${classVar}Service.add(${classVar});
        return R.ok();
    }
    
    /**
    * 修改${table.comment!}
    */
    // @PreAuthorize("@ss.hasPermi('${classVar}:edit')")
    @Log(title = "修改${table.comment!}", businessType = BusinessType.UPDATE)
    @PutMapping
<#if swagger>
    @ApiOperation(value="修改")
</#if>
    public R edit(@RequestBody @Validated <#if need_saveDto>${saveDtoClassName}<#else>${entity}</#if> ${classVar}){
        ${classVar}Service.update(${classVar});
        return R.ok();
    }
    
    /**
    * 删除${table.comment!}
    */
    // @PreAuthorize("@ss.hasPermi('${classVar}:remove')")
    @Log(title = "删除${table.comment!}", businessType = BusinessType.DELETE)
    @DeleteMapping
<#if swagger>
    @ApiOperation(value="删除${table.comment!}")
</#if>
    public R remove(@RequestBody <#list table.fields as field><#if field.keyFlag><#--主键java类型-->List<${field.columnType.type}> idList</#if></#list>){
        ${classVar}Service.delete(idList);
        return R.ok();
    }
 }
